ChkBugReport工具 for Android 2

chkbugreport扩展功能

Extending chkbugreport

  1. Java plugin:需要自己添加插件功能扩展 ExternalPlugin,并实现 initExternalPlugin 函数。麻烦,还需要 jar 文件~~~

  2. XML Plugin:只需 xml 要按照特定格式配置就可,但是功能有局限性。

jar 文件或 xml 文件都需要放到特定文件夹目录下~/.chkbugreport 。这个一看是Linux下的,其实java获取的是”user.home”目录,在Windows上运行可以看到是

public static void main(String[] args) {
//new Main().run(args);
System.out.println(System.getProperty(“user.home”));
}

运行结果:C:\Users\Administrator

在 C:\Users\Administrator 创建.chkbugreport,直接是创建不成功的需要使用 “.chkbugreport.” 。

XML Plugin 扩展功能
—————

可以使用xml文件格式的插件扩展/更改功能。

### 运行 Plugin

运行 Plugin 步骤(Module.java 中 runPlugins() 函数):

First, sort the plugins based on prio– 排序 Resetting and initializing data– 重置/初始化数据

Installing hooks– 安装hooks Then plugin should process the input data first– 处理Plugin输入的数据

* Finally, each plugin should save the generated data–最后生成报告文件


主要是最后三步的扩展功能。

### 添加 XML plugin 插件

代码添加 XML plugin 插件流程:
BugReportModule.java -> Module.java -> loadExternalPlugins() -> loadExternalXmlPlugin(File f) -> addPlugin(new ExtXMLPlugin(xml))

1、创建在 C:\Users\Administrator.chkbugreport 目录


2、添加 xml 文件example.xml:




            <note text="Screen turning on" error="true" />
        </filter>
        <filter matchMsg="com.google.android.youtube">
            <!-- Add a yellow side-note to the log -->
            <note text="YouTube" />
        </filter>
        <filter matchTag="ConnectivityService" matchMsg="Ignoring protectedNetwork">
            <!-- Create a link from the "Errors" chapter -->
            <bug title="Something's fishy" text="Lok at the log. Can you believe it?!" prio="100" type="phone err" />
        </filter>
        <filter matchMsg="com.android.server.backup.BackupManagerService">
            <!-- Delete log lines -->
            <hide />
        </filter>
    </hook>

    <hook into="EventLogPlugin">
        <filter matchMsg="games.provider.NotificationStubContentProvider">
            <!-- Add a red side-note to the log -->
            <!--note text="reboot" error="true" /-->
            <bug title="games.provider.NotificationStubContentProvider" text="Lok at the log. Can you believe it?!" prio="100" type="phone err" />
        </filter>
    </hook>

    <generate>
        <chapter name="WTSpecialcharacters/Subchapter">
            <text>WTSpecialcharacters/Subchapter</text>
            <log>
                <filter log="event" matchTag="battery_level" />
                <filter log="system" matchMsg="kill " />
                <filter log="main" matchTag="PackageManager" />
            </log>
        </chapter>
    </generate>
</plugin>

3、cmd 中运行 chkbugreport …..\bugreport_1542589813841.txt,查看报告……\bugreport_1542589813841_out/index.html

XML plugin 插件中xml文件标签详情

<plugin name="ExamplePlugin">
    <hook into="SystemLogPlugin">
        ...
    </hook>
    <load>
        ...
    </load>
    <generate>
        <chapter name="WTSpecialcharacters/Subchapter">
            ...
        </chapter>
    </generate>
</plugin>

官方文档Xml plugins

hook

hook用于修改已存在插件的行为。依赖于目标插件,也就是源码中定义的 plugin。从github wiki上看并不是支持全部的plugin,仅仅只有BatteryInfoPlugin、SystemLogPlugin、MainLogPlugin 和 EventLogPlugin。

●BatteryInfoPlugin扩展,支持在电池图表中添加额外的信息。但是在生成的HTML报告中并没有发现有变化,可能 plugin 本身功能齐全。BatteryInfoPlugin 有单独的 hooks.java 文件。

<hook into="BatteryInfoPlugin">
    <logchart>
        <dataset id="batt" name="Battery" type="state" colors="#fc8,#00f,#0f0,#f00" />
        <filter log="event" matchTag="battery_status" matchMsg="..*,.*,.*,(.*),.*\]" dataset="batt" />
    </logchart>
</hook>

● SystemLogPlugin, MainLogPlugin and EventLogPlugin 这三个都继承 LogPlugin.java。

<hook into="SystemLogPlugin">
    <filter matchTag="WindowManager" matchMsg="Screen turning on">
        <!-- Add a red side-note to the log -->
        <note text="Screen turning on" error="true" />
    </filter>
    <filter matchMsg="com.google.android.youtube">
        <!-- Add a yellow side-note to the log -->
        <note text="YouTube" />
    </filter>
    <filter matchTag="ConnectivityService" matchMsg="Ignoring protectedNetwork">
        <!-- Create a link from the "Errors" chapter -->
        <bug title="Something's fishy" text="Lok at the log. Can you believe it?!" prio="100" type="phone err" />
    </filter>
    <filter matchMsg="com.android.server.backup.BackupManagerService">
        <!-- Delete log lines -->
        <hide />
    </filter>
</hook>

hook子标签:

1、filter关注标签matchTag、matchMsg。matchTag 对应Android Log中的TAG;matchMsg 对应Android Log中的msg。根据这两个标签过滤。

2、子标签note 、bug 、hide 对 SystemLogPlugin 扩展,即对HTML报告中 system log/log 处理。note 是添加右侧报告的左侧提示 tag,如 “YouTube” 提示;bug 是对 system log/log 过滤 log,并生成到到HTML报告 Errors/ 中;hide 是对 system log/log 过滤 log 隐藏,不可见。

Load

目前没有使用。
github官方:The “load” tag is used only to collect data. Currently it’s not used. In the future it will be used to create tables in the databases and populate it from the log or from other data source.

Generate

<generate>
    <chapter name="WTSpecialcharacters/Subchapter">
        <text>WTSpecialcharacters/Subchapter</text>
        <log>
            <filter log="event" matchTag="battery_level" />
            <!-- filter log="event" matchTag="screen_toggled" / -->

            <filter log="system" matchMsg="kill " />

            <filter log="main" matchTag="PackageManager" />
        </log>
    </chapter>
</generate>

在HTML报告左侧目录中添加目录章节。

generate子标签:

  1. chapter 根据该标签 name 生成目录

  2. text 生成的目录下的报告中,提示语句。

  3. log 生成的目录下生成 log 报告。从代码中查看仅仅支持even、system、main,即HTML报告中 Even log/Log、System log/Log、Main log/Log 过滤

chkbugreport 对 Kernel log 、Last kmsg 支持

在HTML报告中只是抓取 bugreport.txt 中 KERNEL LOG、LAST KMSG 的 log。

对应源码 KernelLogPlugin, 相较于 SystemLogPlugin MainLogPlugin EventLogPlugin (即 LogPlugin)没有实现覆盖父类的 public void onHook(Module mod, XMLNode hook) ,可能由于此,不能支持 hook扩展; 由于 com.sonyericsson.chkbugreport.plugins.extxml.Log.java 中对 generate/chapter/log/filter 标签下的 log 过滤,kernellog 不能支持 generate扩展。

目前xml扩展功能并不能支持kernellog

待续。。。。。。能否扩展到kernellog上

评论

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×